package demo1;

import java.util.Arrays;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-09
 * Time: 21:16
 */
public class Test3 {

    public static void main(String[] args) {
        String str1 = "192.168.111";
        String[] ret = str1.split("\\.");
        System.out.println(Arrays.toString(ret));
    }

    public static void main6(String[] args) {
        //字符串的拆分split,返回数组
        String str1 = "abc&def-hij";
        String[] ret = str1.split("&");
        String[] ret2 = str1.split("&", 2);//最大分2组


    }

    public static void main5(String[] args) {
        //字符串替换
        String str1 = "abcdab";
        String ret1 = str1.replace('a', 'l');//把a替换l
        System.out.println(ret1);
        String ret2 = str1.replace("ab", "kkk");//把出现过的字符串"ab"替换为"kkk"
        System.out.println(ret2);

        String ret3 = str1.replaceFirst("ab", "kkk");//替换字符串的第一个ab,替换为kkk

        String ret4 = str1.replaceAll("a", "kkk");//字符串整体替换
        System.out.println(ret4);
    }

    public static void main4(String[] args) {
        //把字符串 转为数组
        String str1 = "abcd";
        char[] array = str1.toCharArray();
    }

    public static void main3(String[] args) {
        //大小写转换toLowerCase,toUpperCase,是返回新的字符串,不是在原地转换
        String str1 = "ABC";
        String str2 = "def";
        String ret1 = str1.toLowerCase();
        String ret2 = str1.toUpperCase();

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(ret1);
        System.out.println(ret2);
    }

    public static void main2(String[] args) {
        //valueOf把参数转成字符串(包括对象)
        String str1 = String.valueOf(1234);
        String str2 = String.valueOf(true);
        String str3 = String.valueOf(1.2);

        //parseInt把字符串转换成数字
        int data1 = Integer.parseInt("1234");
        Double data2 = Double.parseDouble("12.1");

    }

    public static void main1(String[] args) {
        String str1 = "abc";
        String str2 = "bcd";
        String str3 = "BCD";
    }

}
